home *** CD-ROM | disk | FTP | other *** search
- #include "BuilderWindow.h"
- #include "BuilderMethods/BuilderMethods.h"
- #include "Menus/MenuStuff.h"
- #include "AmigaMem.h"
- #include "project.h"
- #ifndef __GNUC__
- #include <clib/exec_protos.h>
- #include <clib/graphics_protos.h>
- #include <clib/intuition_protos.h>
- #endif
- #ifdef __GNUC__
- #include <proto/exec.h>
- #include <proto/graphics.h>
- #include <proto/intuition.h>
- #endif
- #ifdef __SASC
- #include <proto/exec.h>
- #include <proto/graphics.h>
- #include <proto/intuition.h>
- #endif
-
- #define SELF &self->pw
-
- void
- BuilderWindow_AddPObjectButDontRender( BuilderWindow *self,
- GraphicObject *obj )
- {
- Point location;
- /* EDB */
- /* Additions for snapping objects inside window borders */
- Point window_size, object_size;
- Window *iwindow;
- short leftborder, rightborder, topborder, bottomborder;
-
- iwindow = iWindow( &self->pw );
- leftborder = iwindow->BorderLeft;
- rightborder = iwindow->BorderRight;
- topborder = iwindow->BorderTop;
- bottomborder = iwindow->BorderBottom;
-
- window_size = Size( (GraphicObject *)&self->pw );
-
- location = Location( obj );
- object_size = Size( obj );
- if( ( location.x > leftborder ) &&
- ( ( location.x + object_size.x) < (window_size.x - rightborder) ) )
- {
- /* if object is within window borders */
- if (self->eb.gridinfo)
- location = GridSnap( location, self->eb.gridinfo->location );
- }
-
- else /* snap to inside left or right window border */
- {
- if( location.x > leftborder )
- /* right of left border, snap to right border */
- location.x = (window_size.x - rightborder) - object_size.x;
- else /* snap to left border */
- location.x = leftborder;
- }
-
- if( ( location.y > topborder ) &&
- ( (location.y + object_size.y) < (window_size.y - bottomborder) ) )
- {
- /* if object is within window borders */
- if (self->eb.gridinfo)
- location = GridSnap( location, self->eb.gridinfo->location );
- }
- else /* snap to inside top or bottom window border */
- {
- if( location.y > topborder )
- /* below top border, snap to bottom */
- location.y = window_size.y - bottomborder - object_size.y;
- else /* snap to top border */
- location.y = topborder;
- }
-
- SetLocation( obj, location.x, location.y );
- AddWindowPObject( (struct pcgWindow *)self, obj );
- }
-
- void
- BuilderWindow_AddPObject( BuilderWindow *self,
- GraphicObject *obj )
- {
- BuilderWindow_AddPObjectButDontRender( self, obj );
- Render( (struct GraphicObject *)SELF, NULL );
- }
-
- void BuilderWindow_CleanUp( BuilderWindow *self )
- {
- GraphicObject *obj;
-
- while( ( obj = (struct GraphicObject *)self->pw.FirstInteractor ) != NULL )
- {
- RemoveWindowPObject( (struct pcgWindow *)self, obj );
- if( obj != (GraphicObject*) &self->eb )
- {
- Free( (struct PObject *)obj );
- }
- else
- {
- CleanUp( (struct PObject *)obj );
- }
- }
-
- while( ( obj = self->pw.FirstGraphic ) != NULL )
- {
- RemoveWindowPObject( (struct pcgWindow *)self, obj );
- Free( (struct PObject *)obj );
- }
- }
-
- void BuilderWindow_PObjectToFront( BuilderWindow *self, GraphicObject *obj )
- {
- GraphicObject *gfxobj, *first_obj;
- GraphicObject **start_of_chain;
-
- if( isa( (struct PObject *)obj, InteractorClass() ) )
- {
- start_of_chain = (GraphicObject **)&self->eb.Next;
- /* The EditBox is always the FIRST interactor */
- }
- else /* must be a graphic. */
- {
- start_of_chain = &self->pw.FirstGraphic;
- }
-
- first_obj = *start_of_chain;
- if( first_obj != obj ) /* already at start. */
- {
- for( gfxobj = first_obj; gfxobj != NULL; gfxobj = gfxobj->Next )
- {
- if( gfxobj->Next == obj )
- {
- gfxobj->Next = obj->Next;
- *start_of_chain = obj;
- obj->Next = first_obj;
- break;
- }
- }
- }
-
- Project_Modify();
-
- }
-
- void BuilderWindow_PObjectToBack( BuilderWindow *self, GraphicObject *obj )
- {
- GraphicObject *gfxobj;
- GraphicObject **start_of_chain;
-
- if( isa( (struct PObject *)obj, InteractorClass() ) )
- {
- start_of_chain = (GraphicObject **)&self->eb.Next;
- }
- else /* must be a graphic. */
- {
- start_of_chain = &self->pw.FirstGraphic;
- }
-
-
- /* Remove object. */
- if( *start_of_chain == obj ) /* already at start. */
- {
- *start_of_chain = obj->Next;
- obj->Next = NULL;
- }
- else
- {
- for( gfxobj = *start_of_chain; gfxobj != NULL; gfxobj = gfxobj->Next )
- {
- if( gfxobj->Next == obj )
- {
- gfxobj->Next = obj->Next;
- obj->Next = NULL;
- break;
- }
- }
- }
-
- /* Now that object has been removed, add to tail of chain. */
- if( *start_of_chain == NULL )
- {
- *start_of_chain = obj;
- }
- else
- {
- for ( gfxobj = *start_of_chain;
- gfxobj->Next != NULL;
- gfxobj = gfxobj->Next );
-
- gfxobj->Next = obj;
- }
-
- Project_Modify();
-
- }
-
-
- BOOL BuilderWindow_TestForHit( GraphicObject *self, Point coord )
- {
- Point size, location;
-
- location = Location( self );
- size = Size( self );
-
- return( (BOOL)( ( coord.x >= location.x ) && ( coord.x < ( location.x+size.x ) ) &&
- ( coord.y >= location.y ) && ( coord.y < ( location.y+size.y ) ) ) );
- }
-
- GraphicObject *BuilderWindow_FindPObject( BuilderWindow *self,
- Point coord )
- {
- GraphicObject *obj;
-
- /* Search Interactors first. */
- for( obj = self->eb.Next; obj != NULL; obj = obj->Next )
- {
- if( BuilderWindow_TestForHit( obj, coord ) )
- return obj;
- }
-
- for( obj = self->pw.FirstGraphic; obj != NULL; obj = obj->Next )
- {
- if( BuilderWindow_TestForHit( obj, coord ) )
- return obj;
- }
-
- return NULL;
- }
-
-
- void BuilderWindow_AddInteractor( BuilderWindow *self,
- Interactor *interactor )
- {
- Interactor *iactor;
- ULONG flags;
-
- SetInteractorWindow( interactor, SELF );
-
-
- /* add this interactor to chain of interactors. */
- if( self->pw.FirstInteractor )
- {
- for( iactor = self->pw.FirstInteractor;
- iactor->Next != NULL;
- iactor = iactor->Next );
-
- iactor->Next = interactor;
- }
- else
- self->pw.FirstInteractor = interactor;
-
- /* Add IDCMP flags */
-
- flags = IDCMPFlags( (struct Interactor *)SELF ) | IDCMPFlags( interactor );
- SetIDCMPFlags( SELF, flags );
- }
-
-
- void BuilderWindow_RemoveInteractor( BuilderWindow *self,
- Interactor *interactor )
- {
- Interactor *iactor;
-
- SetInteractorWindow( interactor, NULL );
-
- if( self->pw.FirstInteractor )
- {
- if( self->pw.FirstInteractor == interactor )
- {
- self->pw.FirstInteractor = interactor->Next;
- }
- else
- {
- for( iactor = self->pw.FirstInteractor;
- iactor != NULL;
- iactor = iactor->Next )
- {
- if( iactor->Next == interactor )
- {
- iactor->Next = interactor->Next;
- break;
- }
- }
- }
- }
- interactor->Next = NULL;
-
- Project_Modify();
- }
-
- UWORD BuilderWindow_Respond( BuilderWindow *self, IntuiMessage *event )
- {
- UWORD response = 0;
- Window *w;
-
-
- w = event->IDCMPWindow;
-
- switch( event->Class )
- {
- case REFRESHWINDOW:
- if( w == self->pw.Window )
- {
- BeginRefresh( self->pw.Window );
- Refresh( (struct Interactor *)SELF );
- EndRefresh( self->pw.Window, TRUE );
- }
- response = RESPONDED;
- break;
-
- case NEWSIZE:
- response = RESPONDED;
- Project_Modify();
- break;
-
- default:
- response = Respond( (struct Interactor *)&self->eb, event );
-
- }
- return response;
- }
-
-
- void BuilderWindow_Refresh( BuilderWindow *self )
- {
- GraphicObject *graphic;
- Interactor *interactor;
- RastPort *rport;
- struct Window *iwindow;
-
- if( iwindow = iWindow( SELF ) )
- {
- RefreshWindowFrame( iwindow );
-
- rport = RPort( SELF );
-
- /* Draw window graphics */
- for( graphic = self->pw.FirstGraphic;
- graphic != NULL;
- graphic = graphic->Next )
- {
- Render( graphic, rport );
- }
-
- /* Draw interactors *** Draw EditBox LAST! */
- for ( interactor = self->eb.Next;
- interactor != NULL;
- interactor = interactor->Next )
- {
- Refresh( interactor );
- }
-
- Refresh( (struct Interactor *)&self->eb );
- }
- }
-
-
- #include "BuilderMethods/BuilderWindow_builder.h"
-
- struct BuilderMethods BuilderWindow_bm;
-
- BOOL BuilderWindow_elaborated = FALSE;
-
- struct pcgWindowClass BuilderWindow_Class;
-
- void BuilderWindowClass_Init( struct pcgWindowClass *class )
- {
- pcgWindowClass_Init( class );
- class->isa = pcgWindowClass();
- class->ClassName = "my_window";
- class->CleanUp = (void(*)(PObject *))BuilderWindow_CleanUp;
- class->AddInteractor = (void(*)(struct pcgWindow *, struct Interactor *))BuilderWindow_AddInteractor;
- class->RemoveInteractor = (void(*)(struct pcgWindow *, struct Interactor *))BuilderWindow_RemoveInteractor;
- class->BuilderMethods = &BuilderWindow_bm;
- class->Refresh = (void(*)(Interactor *))BuilderWindow_Refresh;
- class->Respond = (USHORT(*)(Interactor *, IntuiMessage *))BuilderWindow_Respond;
-
- BuilderWindow_bm.PropEdit = (void(*)(struct GraphicObject *,struct pcgWindow *,pcg_3DPens))BuilderWindow_PropEdit;
- BuilderWindow_bm.WriteCode = (void(*)(struct GraphicObject *,struct BuilderWindow *,FILE *,UWORD))BuilderWindow_WriteCode;
-
- }
-
-
- struct pcgWindowClass *BuilderWindowClass( void )
- {
- if( ! BuilderWindow_elaborated )
- {
- BuilderWindowClass_Init( &BuilderWindow_Class );
- BuilderWindow_elaborated = TRUE;
- }
-
- return &BuilderWindow_Class;
- }
-
-
-
- void BuilderWindow_Init( BuilderWindow *self,
- UWORD leftedge,
- UWORD topedge,
- UWORD width,
- UWORD height,
- pcg_3DPens pens,
- char *title,
- struct Screen *screen,
- GridInfo *gridinfo )
- {
-
- pcgWindow_Init( SELF, leftedge, topedge, width, height,
- 100, 50, 65535, 65535, title,
- CLOSEWINDOW | REFRESHWINDOW | MENUPICK | MENUVERIFY | NEWSIZE,
- ACTIVATE | SIMPLE_REFRESH | WINDOWCLOSE | WINDOWDEPTH | WINDOWDRAG
- | WINDOWSIZING | SIZEBBOTTOM ,
- screen );
-
- self->pw.isa = BuilderWindowClass();
- self->IDCMPFlags = REFRESHWINDOW | CLOSEWINDOW;
- Editor_Init( &self->eb, pens, gridinfo );
- AddWindowPObject( (struct pcgWindow *)SELF, (struct GraphicObject *)&self->eb );
-
- GiveItAName( (struct PObject *)self );
- }
-
-